<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <div id="syn" style="width: 600px;height:400px;"></div>

    <script src='http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js'></script>
    <script src='./echarts.js'></script>
    <script>
        var synChart = echarts.init(document.getElementById('syn'));

        synChart.setOption({
            title: {
                text: '异步数据加载示例'
            },
            tooltip: {},
            legend: {
                data: ['销量']
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: []
            }]
        });
        // 异步加载数据
        $.get('./data.json', function (result) {
            // 填入数据
            synChart.setOption({
                xAxis: {
                    data: result.name
                },
                series: [{
                    // 根据名字对应到相应的系列
                    name: '销量',
                    data: result.sales
                }]
            });
        });
        
    </script>
</body>

</html>